package com.taotao.job.core.enums;


import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * 任务启动类型
 *
 * @author fanbeibei
 * @version 1.0
 * @date 2021/2/3 17:05
 */
@Getter
@AllArgsConstructor
public enum StartType {

    /**
     * 定时启动
     */
    CRON_START(1, "定时启动"),
    /**
     * 上级拉起
     */
    PRE_TRIGGER(2, "上级拉起"),
    /**
     * 手动触发
     */
    MANUAL_START(3, "手动触发"),
    /**
     * 延时启动
     */
    DELAY_START(777, "延时启动")
    ;

    private Integer code;

    private String text;


    private static final Map<Integer, StartType> codeTextMap = new HashMap<>();

    static {
        StartType[] values = StartType.values();
        for (StartType val : values) {
            codeTextMap.put(val.code, val);
        }
    }


    public static StartType getByCode(Integer code) {
        return codeTextMap.get(code);
    }

    public static String getTextByCode(Integer code) {
        StartType v = getByCode(code);

        if (null == v) {
            return "未知Code:" + code;
        }
        return v.text;
    }


}
